﻿FlyTalk.views.SearchView = Ext.extend(Ext.form.FormPanel, {

	
    initComponent: function () {
		// back button on toolbar
		this.backButton = new Ext.Button({
			text: 'Back',
			ui: 'back',
			handler: this.backButtonTap,
			scope: this
		});
		
		this.searchButton = new Ext.Button({
            text: 'Search',
            ui: 'action',
            handler: this.searchButtonTap,
            scope: this
        });
		
		// top tool bar
		this.searchToolbar = new Ext.Toolbar({
			title: 'Search',
			
			items:[
				this.backButton,
				{ xtype: 'spacer' },
				this.searchButton,
			]
			
		});

        this.dockedItems = [this.searchToolbar];

        FlyTalk.views.SearchView.superclass.initComponent.call(this);
    },	

    backButtonTap: function () {
		this.reset();
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'toTweetDeck1'
        });
    },
	
	searchButtonTap: function () {
		var searchField = Ext.getCmp('searchfield').getValue();
		var scopeSelect = Ext.getCmp("scopeselect").getValue();
		this.reset();
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'searchPosts',
			keyword: searchField,
			scope: scopeSelect,
        });
    },
	
	scroll: false,
	
    items: [
	{ // serach in
        xtype: 'textfield',
        name: 'search',
		id: 'searchfield',
        label: 'Search',
        required: true
   	},
	{ // search from (scope)
		 xtype: 'selectfield',
		 name: 'scope',
		 id: 'scopeselect',
		 label: 'Search in comments from: ',
		 labelWidth: 300,
		 labelAlign: 'top',
		 style: 'margin-top: 20px',
    	 options: [
       		{text: 'my flight',  value: '@flight'},
       		{text: 'my airline', value: '@airline'},
       		{text: 'my terminal',  value: '@terminal'},
			{text: 'all airport',  value: '@airport'}
    		]
	},
	]
});

